#ifndef SENSOR_MANAGER_H
#define SENSOR_MANAGER_H

#include <Arduino.h>

// 传感器类
class SensorManager {
private:
  int trigPin, echoPin, tempPin;
  unsigned long lastUpdate;

public:
  SensorManager(int trig, int echo, int temp) {
    trigPin = trig;
    echoPin = echo;
    tempPin = temp;
    lastUpdate = 0;
  }

  void init() {
    pinMode(trigPin, OUTPUT);
    pinMode(echoPin, INPUT);
  }

  float getDistance() {
    digitalWrite(trigPin, LOW);
    delayMicroseconds(2);
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(trigPin, LOW);

    long duration = pulseIn(echoPin, HIGH);
    return duration * 0.034 / 2;
  }

  float getTemperature() {
    int reading = analogRead(tempPin);
    return (reading * 5.0 / 1024.0) * 100;
  }

  bool shouldUpdate() {
    return millis() - lastUpdate > 200;
  }

  void updateLastUpdate() {
    lastUpdate = millis();
  }
};

#endif // SENSOR_MANAGER_H